import re
import requests
from bs4 import BeautifulSoup
import execjs

file = open("kg_mid.js", 'r', encoding='utf-8')
js_code = execjs.compile(file.read())
kg_mid = js_code.call('test2')
print(kg_mid)
# url1 = 'https://www.kugou.com/yy/html/rank.html?from=homepage'
# heads = {
#     'Cookie':
#         'kg_mid=dc370b50f7e664570b2fb6428ff92e59; ACK_SERVER_10015=%7B%22list%22%3A%5B%5B%22gzlogin-user.kugou.com%22%5D%5D%7D; kg_dfid=2mRfl53jlyVu3wtekx0oAAxM; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1752977133; HMACCOUNT=79A595DB8974E799; KuGoo=KugooID=2378814979&KugooPwd=843456140ED849E521D3D38EED8EC949&NickName=%u0032%u0033%u0037%u0038%u0038%u0031%u0034%u0039%u0037%u0039&Pic=&RegState=1&RegFrom=&t=a33537ad939e6713f886e7e38337b30a0857476f796dcbf0ce81a46f0a57ee67&t_ts=1752977978&t_key=&a_id=1014&ct=1752977977&UserName=%u0032%u0033%u0037%u0038%u0038%u0031%u0034%u0039%u0037%u0039; KugooID=2378814979; t=a33537ad939e6713f886e7e38337b30a0857476f796dcbf0ce81a46f0a57ee67; a_id=1014; UserName=%u0032%u0033%u0037%u0038%u0038%u0031%u0034%u0039%u0037%u0039; mid=dc370b50f7e664570b2fb6428ff92e59; dfid=2mRfl53jlyVu3wtekx0oAAxM; kg_mid_temp=dc370b50f7e664570b2fb6428ff92e59; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1752978750; ACK_SERVER_10016=%7B%22list%22%3A%5B%5B%22gzreg-user.kugou.com%22%5D%5D%7D; ACK_SERVER_10017=%7B%22list%22%3A%5B%5B%22gzverifycode.service.kugou.com%22%5D%5D%7D',
#     'User-Agent':
#         'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 SLBrowser/9.0.6.5061 SLBChan/105 SLBVPV/64-bit'
# }
# title_url = {}
# r = requests.get(url1, headers=heads)
# soup = BeautifulSoup(r.text, 'html.parser')
# div1 = soup.find('div', id='rankWrap')
# div1 = div1.find('ul').find_all('li')
# for div2 in div1:
#     data = div2.find('a')
#     # print(data.get('href'))
#     # print(data.get('title'))
#     title_url[data.get('title')] = data.get('href')
# hash_list = []
# mid_list = []
# hash_re = re.compile('"hash":"(.*?)","timelength', re.I | re.M)
# mid_re = re.compile('<audio class="music" id="myAudio" src="(.*?)" preload="auto" data-hash="63D23D7AA90E08EE1983BB48F6F5F07F" data-ecid="cshzbzd2"> ', re.I | re.M)
# for k, v in title_url.items():
#     r2 = requests.get(v, headers=heads)
#     hash_data = re.findall(hash_re, r2.text)
#     mid_data = re.findall(mid_re, r2.text)
#     hash_list.append(hash_data[0])
#     # print(hash_data)
#     print(mid_data)
# url = 'https://wwwapi.kugou.com/play/songinfo'
# for hash in hash_list:
#     params = {
#         'srcappid': 2919,
#         'clientver': 20000,
#         'clienttime': 1752977985692,
#         'mid': 'dc370b50f7e664570b2fb6428ff92e59',
#         'uuid': 'dc370b50f7e664570b2fb6428ff92e59',
#         'dfid': '2mRfl53jlyVu3wtekx0oAAxM',
#         'appid': 1014,
#         'platid': 4,
#         'encode_album_audio_id': 'cshzbzd2',
#         'token': 'a33537ad939e6713f886e7e38337b30a0857476f796dcbf0ce81a46f0a57ee67',
#         'userid': 2378814979,
#         'signature': 'e0260a9d7fee4154cfb9936476c29412'
#     }
# mp3_url = 'https://webfs.kugou.com/202507201048/8667c5cafa41763984cdab97a6a4218f/v3/63d23d7aa90e08ee1983bb48f6f5f07f/yp/full/ap1014_us2378814979_mii0w1iw8z2ai2iphcu80ooo2ki81120_pi406_mx773462303_s3228765949.mp3'
#
